<template>
    <div style="padding: 10px;">
        <el-form :model="formData" ref="queryForm" :inline="true" :rules="Rules" label-width="auto"
                 @submit.native.prevent>
            <!-- <el-form-item label="对应新品开发id" desc="对应新品开发id" prop="bpmId">
                 <el-input v-model.trim="formData.bpmId" placeholder="对应新品开发id" clearable size="small"
                           style="width:120px;" />
             </el-form-item>-->
            <!--  <el-form-item label="对应业务流程节点id" desc="对应业务流程节点id" prop="bpmNodeId">
                  <el-input v-model.trim="formData.bpmNodeId" placeholder="对应业务流程节点id" clearable size="small"
                            style="width:120px;" />
              </el-form-item>
              <el-form-item label="节点标识" desc="节点标识" prop="nodeCode">
                  <el-input v-model.trim="formData.nodeCode" placeholder="节点标识" clearable size="small"
                            style="width:120px;" />
              </el-form-item>-->
            <!--  <el-form-item label="节点深度" desc="节点深度" prop="deep">
                  <el-input v-model.trim="formData.deep" placeholder="节点深度" clearable size="small" style="width:120px;" />
              </el-form-item>-->
            <el-form-item label="执行器名称" desc="执行器名称" prop="handleId">
                <!--   <el-input v-model.trim="formData.handleCode" placeholder="执行器名称" clearable size="small"
                             style="width:120px;" />-->
                <!--下拉选中  执行器-->
                <bpmPipelineHandleSelect
                        style="width:120px;"
                        v-model.trim="formData.handleId"
                        :text.sync="formData.handleName"
                        placeholder="选执行器"
                        @change="_data=>{
                            formData.handleName=formData.name
                            formData.handleCode=formData.code
                        }"
                />
            
            </el-form-item>
            <!--        <el-form-item label="后置执行器ID" desc="后置执行器ID" prop="handleId">
                        <el-input v-model.trim="formData.handleId" placeholder="后置执行器ID" clearable size="small"
                                  style="width:120px;" />
                    </el-form-item>-->
            <el-form-item label="执行阶段" desc="执行阶段 1、节点生成、 2、节点指派、3、节点接单、4、节点开始、5、资料校验、6、节点结束" prop="handleStage">
                <dic-select :code="dicInner.mes_bpm_pipiline_handle_handleStage"
                            v-model.trim="formData.handleStage"
                            placeholder="执行阶段 " clearable size="small"
                            style="width:120px;"
                ></dic-select>
            </el-form-item>
            <!-- <el-form-item label="状态" desc="状态 1 正常  5暂停 10废除" prop="state">
                 <dic-select v-model="formData.state" :code="dicInner.mes_bpm_pipeline_handle_state"
                             placeholder="状态 1 正常  5暂停 10废除" clearable size="small" style="width:120px;" />
             </el-form-item>-->
        </el-form>
    </div>
</template>
<script>
import { getUrlParam } from '@/utils/index';
import { alertWithPaylod, alertFail } from '@/utils/alertUtil';
import * as  api from '@/apis/mesBpmPipelineHandle.api.js';
import { default as FormDialog } from '@codegenarate/mydialogplus';
import { fillData, validatePromise } from '@/utils/index';
import { findOne } from '@/utils/lodash';
import { lodashEmpty } from '@/utils/lodashUtil';

const Rules = {
  'id': [{ required: false, message: '主键ID', trigger: 'blur' }],
  'bpmId': [{ required: false, message: '对应新品开发id', trigger: 'blur' }],
  'bpmNodeId': [{ required: false, message: '对应业务流程节点id', trigger: 'blur' }],
  'nodeCode': [{ required: false, message: '节点标识', trigger: 'blur' }],
  'deep': [{ required: false, message: '节点深度', trigger: 'blur' }],
  'handleCode': [{ required: false, message: '后置执行器标识码', trigger: 'blur' }],
  'handleId': [{ required: true, message: '后置执行器ID', trigger: 'blur' }],
  'handleStage': [{ required: true, message: '执行阶段', trigger: 'blur' }],
  'state': [{ required: false, message: '状态', trigger: 'blur' }],
  'remarks': [{ required: false, message: '备注', trigger: 'blur' }],
  'tenantType': [{ required: false, message: '租户类型', trigger: 'blur' }],
  'tenantId': [{ required: false, message: '租户ID', trigger: 'blur' }],
  'delState': [{ required: false, message: '有效状态[数据字典=del_state]', trigger: 'blur' }],
  'addUser': [{ required: false, message: '添加人', trigger: 'blur' }],
  'addUserId': [{ required: false, message: '添加人ID', trigger: 'blur' }],
  'addTime': [{ required: false, message: '添加时间', trigger: 'blur' }],
  'editUser': [{ required: false, message: '最近更新人', trigger: 'blur' }],
  'editUserId': [{ required: false, message: '最近更新人ID', trigger: 'blur' }],
  'lastEditTime': [{ required: false, message: '最近更新时间', trigger: 'blur' }],
  'serverNumber': [{ required: false, message: '服务器编号ID', trigger: 'blur' }],
};
const dicInner = {
  'mes_bpm_pipiline_handle_handleStage': 'mes_bpm_pipiline_handle_handleStage',
  '___mes_bpm_pipeline_handle_id': '主键ID',
  'mes_bpm_pipeline_handle_id': 'mes_bpm_pipeline_handle_id',
  '___mes_bpm_pipeline_handle_bpmId': '对应新品开发id',
  'mes_bpm_pipeline_handle_bpmId': 'mes_bpm_pipeline_handle_bpmId',
  '___mes_bpm_pipeline_handle_bpmNodeId': '对应业务流程节点id',
  'mes_bpm_pipeline_handle_bpmNodeId': 'mes_bpm_pipeline_handle_bpmNodeId',
  '___mes_bpm_pipeline_handle_nodeCode': '节点标识',
  'mes_bpm_pipeline_handle_nodeCode': 'mes_bpm_pipeline_handle_nodeCode',
  '___mes_bpm_pipeline_handle_deep': '节点深度',
  'mes_bpm_pipeline_handle_deep': 'mes_bpm_pipeline_handle_deep',
  '___mes_bpm_pipeline_handle_handleCode': '后置执行器标识码',
  'mes_bpm_pipeline_handle_handleCode': 'mes_bpm_pipeline_handle_handleCode',
  '___mes_bpm_pipeline_handle_handleId': '后置执行器ID',
  'mes_bpm_pipeline_handle_handleId': 'mes_bpm_pipeline_handle_handleId',
  '___mes_bpm_pipeline_handle_handleStage': '执行阶段 1、节点生成、 2、节点指派、3、节点接单、4、节点开始、5、资料校验、6、节点结束',
  'mes_bpm_pipeline_handle_handleStage': 'mes_bpm_pipeline_handle_handleStage',
  '___mes_bpm_pipeline_handle_state': '状态 1 正常  5暂停 10废除',
  'mes_bpm_pipeline_handle_state': 'mes_bpm_pipeline_handle_state',
  '___mes_bpm_pipeline_handle_remarks': '备注',
  'mes_bpm_pipeline_handle_remarks': 'mes_bpm_pipeline_handle_remarks',
  '___mes_bpm_pipeline_handle_tenantType': '租户类型 1应用管理者2应用消息者',
  'mes_bpm_pipeline_handle_tenantType': 'mes_bpm_pipeline_handle_tenantType',
  '___mes_bpm_pipeline_handle_tenantId': '租户ID',
  'mes_bpm_pipeline_handle_tenantId': 'mes_bpm_pipeline_handle_tenantId',
  '___mes_bpm_pipeline_handle_delState': '有效状态[数据字典=del_state] 1有效  5删除',
  'mes_bpm_pipeline_handle_delState': 'mes_bpm_pipeline_handle_delState',
  '___mes_bpm_pipeline_handle_addUser': '添加人',
  'mes_bpm_pipeline_handle_addUser': 'mes_bpm_pipeline_handle_addUser',
  '___mes_bpm_pipeline_handle_addUserId': '添加人ID',
  'mes_bpm_pipeline_handle_addUserId': 'mes_bpm_pipeline_handle_addUserId',
  '___mes_bpm_pipeline_handle_addTime': '添加时间',
  'mes_bpm_pipeline_handle_addTime': 'mes_bpm_pipeline_handle_addTime',
  '___mes_bpm_pipeline_handle_editUser': '最近更新人',
  'mes_bpm_pipeline_handle_editUser': 'mes_bpm_pipeline_handle_editUser',
  '___mes_bpm_pipeline_handle_editUserId': '最近更新人ID',
  'mes_bpm_pipeline_handle_editUserId': 'mes_bpm_pipeline_handle_editUserId',
  '___mes_bpm_pipeline_handle_lastEditTime': '最近更新时间',
  'mes_bpm_pipeline_handle_lastEditTime': 'mes_bpm_pipeline_handle_lastEditTime',
  '___mes_bpm_pipeline_handle_serverNumber': '服务器编号ID',
  'mes_bpm_pipeline_handle_serverNumber': 'mes_bpm_pipeline_handle_serverNumber',
};
export default {
  name: 'mesBpmPipelineHandleModify',
  data() {
    return {
      api: api,
      Rules,
      dicInner,
      formData: {
        'id': '',
        'bpmId': '',
        'bpmNodeId': '',
        'nodeCode': '',
        'deep': '',
        'handleCode': '',
        'handleId': '',
        handleName: '',
        'handleStage': '',
        'state': '',
        'remarks': '',
        'tenantType': '',
        'tenantId': '',
        'delState': '',
        'addUser': '',
        'addUserId': '',
        'addTime': '',
        'editUser': '',
        'editUserId': '',
        'lastEditTime': '',
        'serverNumber': '',
      },
      lists: [],
      selectRows: [],
      classId: '',
      classIdPath: '',
      className: '',
      loading: false,
      isFold: false,
      //已经选中的列表
      dataList: [],
      tableRowClassName({ row, rowIndex }) {
        if (row.rowType == 'total') {
          return 'total-row';
        }
        return '';
      },
    };
  },
  components: {
    svgIcon: () => import('@codegenarate/svg-icon'),
    dicSelect: () => import('@/components/dicselect.vue'),
    dicTag: () => import('@/components/DicSelect/dic-tag.vue'),
    bpmPipelineHandleSelect: () => import('@/components/bpmPipelineHandleSelect/index.vue'),
    
  },
  computed: {},
  watch: {},
  methods: {
    /**
     *    @params _data.bpmId
     *     @params _data.bpmNodeId
     *     @params _data.dataList
     *
     * * @desc 初始化
     *  */
    initByDialog(_data) {
      fillData(this.formData, _data);
      this.dataList = _data && _data.dataList || [];
      console.log('初始化数据', this.formData);
    },
    async submitByDialog(_data) {
      var isyes = await validatePromise.call(this, 'queryForm');
      if (!isyes) {
        return { success: false, message: '请检查必填项' };
      }
      //校验 已存在 退出
      if (!lodashEmpty(findOne(this.dataList, item => item.handleStage == this.formData.handleStage))) {
        alertFail('执行阶段已经存在 请选中其他的');
        return { success: false, message: '执行阶段已经存在' };
      }
      
      var func = this.formData.id ? api.update : api.add;
      var result = await func(this.formData);
      alertWithPaylod(result);
      return result;
    },
  },
};</script>
